from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-06-21 14:07:38.186106
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 21, Jun, 2022
Time: 14:07:45
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.5669
Nobs: 694.000 HQIC: -49.9282
Log likelihood: 8631.43 FPE: 1.65022e-22
AIC: -50.1560 Det(Omega_mle): 1.45086e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.298131 0.058253 5.118 0.000
L1.Burgenland 0.108275 0.038088 2.843 0.004
L1.Kärnten -0.109766 0.020159 -5.445 0.000
L1.Niederösterreich 0.214937 0.079578 2.701 0.007
L1.Oberösterreich 0.103492 0.078127 1.325 0.185
L1.Salzburg 0.256683 0.040749 6.299 0.000
L1.Steiermark 0.044665 0.053304 0.838 0.402
L1.Tirol 0.110344 0.043085 2.561 0.010
L1.Vorarlberg -0.057853 0.037362 -1.548 0.122
L1.Wien 0.036356 0.069084 0.526 0.599
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.054835 0.122350 0.448 0.654
L1.Burgenland -0.035634 0.079996 -0.445 0.656
L1.Kärnten 0.041152 0.042339 0.972 0.331
L1.Niederösterreich -0.176337 0.167140 -1.055 0.291
L1.Oberösterreich 0.429761 0.164093 2.619 0.009
L1.Salzburg 0.288425 0.085586 3.370 0.001
L1.Steiermark 0.103255 0.111956 0.922 0.356
L1.Tirol 0.317350 0.090492 3.507 0.000
L1.Vorarlberg 0.028406 0.078472 0.362 0.717
L1.Wien -0.043960 0.145099 -0.303 0.762
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.185912 0.029805 6.238 0.000
L1.Burgenland 0.090106 0.019487 4.624 0.000
L1.Kärnten -0.007706 0.010314 -0.747 0.455
L1.Niederösterreich 0.264006 0.040716 6.484 0.000
L1.Oberösterreich 0.137090 0.039974 3.430 0.001
L1.Salzburg 0.045255 0.020849 2.171 0.030
L1.Steiermark 0.023618 0.027273 0.866 0.387
L1.Tirol 0.090490 0.022044 4.105 0.000
L1.Vorarlberg 0.057192 0.019116 2.992 0.003
L1.Wien 0.115319 0.035347 3.263 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111591 0.030250 3.689 0.000
L1.Burgenland 0.044876 0.019778 2.269 0.023
L1.Kärnten -0.013681 0.010468 -1.307 0.191
L1.Niederösterreich 0.191366 0.041324 4.631 0.000
L1.Oberösterreich 0.303171 0.040571 7.473 0.000
L1.Salzburg 0.106669 0.021161 5.041 0.000
L1.Steiermark 0.105996 0.027680 3.829 0.000
L1.Tirol 0.103102 0.022373 4.608 0.000
L1.Vorarlberg 0.068910 0.019402 3.552 0.000
L1.Wien -0.022861 0.035875 -0.637 0.524
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.133814 0.055397 2.416 0.016
L1.Burgenland -0.050729 0.036220 -1.401 0.161
L1.Kärnten -0.044503 0.019170 -2.321 0.020
L1.Niederösterreich 0.150216 0.075676 1.985 0.047
L1.Oberösterreich 0.143555 0.074297 1.932 0.053
L1.Salzburg 0.284953 0.038751 7.353 0.000
L1.Steiermark 0.051636 0.050690 1.019 0.308
L1.Tirol 0.166595 0.040972 4.066 0.000
L1.Vorarlberg 0.094715 0.035530 2.666 0.008
L1.Wien 0.072129 0.065697 1.098 0.272
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060354 0.043839 1.377 0.169
L1.Burgenland 0.035206 0.028664 1.228 0.219
L1.Kärnten 0.051153 0.015171 3.372 0.001
L1.Niederösterreich 0.212874 0.059888 3.555 0.000
L1.Oberösterreich 0.294145 0.058796 5.003 0.000
L1.Salzburg 0.046071 0.030666 1.502 0.133
L1.Steiermark 0.005552 0.040115 0.138 0.890
L1.Tirol 0.139392 0.032424 4.299 0.000
L1.Vorarlberg 0.074752 0.028118 2.659 0.008
L1.Wien 0.081186 0.051991 1.562 0.118
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.171147 0.052642 3.251 0.001
L1.Burgenland -0.001785 0.034419 -0.052 0.959
L1.Kärnten -0.063002 0.018217 -3.458 0.001
L1.Niederösterreich -0.080329 0.071913 -1.117 0.264
L1.Oberösterreich 0.194195 0.070602 2.751 0.006
L1.Salzburg 0.056067 0.036824 1.523 0.128
L1.Steiermark 0.240822 0.048170 4.999 0.000
L1.Tirol 0.497021 0.038935 12.765 0.000
L1.Vorarlberg 0.045318 0.033763 1.342 0.180
L1.Wien -0.056843 0.062430 -0.911 0.363
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.162959 0.059808 2.725 0.006
L1.Burgenland -0.012967 0.039104 -0.332 0.740
L1.Kärnten 0.064328 0.020697 3.108 0.002
L1.Niederösterreich 0.203670 0.081702 2.493 0.013
L1.Oberösterreich -0.076094 0.080213 -0.949 0.343
L1.Salzburg 0.210308 0.041837 5.027 0.000
L1.Steiermark 0.134574 0.054727 2.459 0.014
L1.Tirol 0.064294 0.044235 1.453 0.146
L1.Vorarlberg 0.119867 0.038359 3.125 0.002
L1.Wien 0.131627 0.070928 1.856 0.063
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.366881 0.034658 10.586 0.000
L1.Burgenland 0.006382 0.022660 0.282 0.778
L1.Kärnten -0.023496 0.011993 -1.959 0.050
L1.Niederösterreich 0.218456 0.047345 4.614 0.000
L1.Oberösterreich 0.202764 0.046482 4.362 0.000
L1.Salzburg 0.043722 0.024244 1.803 0.071
L1.Steiermark -0.017125 0.031713 -0.540 0.589
L1.Tirol 0.106083 0.025633 4.138 0.000
L1.Vorarlberg 0.069499 0.022229 3.127 0.002
L1.Wien 0.028980 0.041102 0.705 0.481
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037405 0.134248 0.191973 0.152392 0.114530 0.099022 0.056262 0.217106
Kärnten 0.037405 1.000000 -0.016846 0.133903 0.055022 0.093231 0.436655 -0.054196 0.093418
Niederösterreich 0.134248 -0.016846 1.000000 0.334174 0.140172 0.292363 0.087800 0.173184 0.311701
Oberösterreich 0.191973 0.133903 0.334174 1.000000 0.226205 0.323475 0.173925 0.159914 0.264476
Salzburg 0.152392 0.055022 0.140172 0.226205 1.000000 0.138027 0.113325 0.137637 0.131833
Steiermark 0.114530 0.093231 0.292363 0.323475 0.138027 1.000000 0.145376 0.126572 0.071845
Tirol 0.099022 0.436655 0.087800 0.173925 0.113325 0.145376 1.000000 0.109264 0.142906
Vorarlberg 0.056262 -0.054196 0.173184 0.159914 0.137637 0.126572 0.109264 1.000000 0.005496
Wien 0.217106 0.093418 0.311701 0.264476 0.131833 0.071845 0.142906 0.005496 1.000000